import { normalize, schema } from 'normalizr';

// 文档中列举了一个博客数据的例子(当然其实这个数据结构已经挺复杂的了)
const blogPosts = [
  {
    id: "post1",
    author: {username: "user1", name: "User 1"},
    body: "sdlfladflalsdfldfsdff",
    comments: [
      {
        id: "comment1",
        author: {username: "user2", name: "User 2"},
        comment: "adsfasdfs..",
      },
      {
        id: "comment2",
        author: {username: "user3", name: "User 3"},
        comment: "...fvcggjhhjhg..",
      }
    ]
  },
  {
    id: "post2",
    author: {username : "user2", name : "User 2"},
    body: "....rettryt..",
    comments: [
      {
        id: "comment3",
        author: {username : "user3", name : "User 3"},
        comment: "...ert..",
      },
      {
        id: "comment4",
        author: {username : "user1", name : "User 1"},
        comment: "ert.erterte....",
      },
      {
        id: "comment5",
        author: {username : "user3", name : "User 3"},
        comment: ".sdfgsdfgsdg....",
      }
    ]
  }
  // 重复很多遍
]


const data = { id_str: '123', url: 'https://twitter.com', user: { id_str: '456', name: 'Jimmy' } };

const user = new schema.Entity('users', {}, { idAttribute: 'id_str' });
const tweet = new schema.Entity(
  'tweets',
  { user: user },
  {
    idAttribute: 'id_str'});

const normalizedData = normalize(data, tweet);
console.log('normalized',normalizedData)


